/**
 * @Author:周邱艳
 * @Date:2020/6/30
 * @Description:这是调仓记录页
 */
import React,{Component} from "react";
import {Icon, NavBar, Tabs, WhiteSpace, List, Button, Toast,Card} from "antd-mobile";
import {URL} from '../../index'
import axios from "axios";
import {Link} from "react-router-dom";
import {getCookieId} from "../Login/Component_Login/GetCookie";

const Item = List.Item;
const Brief = Item.Brief;
var changeList=[];
var dealTime=[]
// 将获取的数据中属性为数字的转换为文字

function numberName(newList){
    for(let i=0;i<newList.length;i++) {
        //规范组合交易时间
        var StringTime=toString(newList[i].gmtModified)

        //修改组合交易状态
        switch (newList[i].adjustStatus) {
            case 0:
                newList[i].adjustStatus = "赎回确认中";
                break;
            case 1:
                newList[i].adjustStatus = "申购确认中";
                break;
            case 2:
                newList[i].adjustStatus = "申购成功";
                break;
            case 3:
                newList[i].adjustStatus = "撤单成功";
                break;
            case 4:
                newList[i].adjustStatus = "赎回成功";
                break;
            case 5:
                newList[i].adjustStatus = "提现成功";
                break;
            case 6:
                newList[i].adjustStatus = "充值成功";
                break;
        }
    }
    return newList;
}
//时间格式转换
function myFunction(datetime){

    var item = new Date(datetime).toJSON();

    var date = new Date(+new Date(item)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'')

    console.log("时间==="+date);
    return date;
}
export default class ChangeList extends Component{
    constructor(props) {
        super(props);
        const accountId=this.props.location.state.accountId
        this.state = {
            adjustmentRecords:[],//json表名
            disabled: false,
            changeList:[],//对象内的数字转化为文字
            accountId:accountId
        }
        this.loadData = this.loadData.bind(this)
    }

    loadData(){
        axios({
            method:"GET",
            url:"http://39.101.141.248:9527/transaction/adjustmentRecordLists",
            params:{
                userId: getCookieId(),
                wealthAccountId:this.state.accountId
            }
        }).then(res=>{
            changeList=numberName(res.data.adjustmentRecords)
            var comBaseName=res.data.comBaseName
            console.log(comBaseName)
            this.setState({
                adjustmentRecords:res.data.adjustmentRecords,
                changeList:changeList,
                comBaseName:comBaseName

            })
        }).catch(error =>{
            console.log(error)
        })
    }
    componentDidMount() {
        this.loadData()
    }

    render() {
        document.title="交易记录"
        return (
            <div>
                {/*页面顶部*/}
                <div style={{position:"fixed",width:"100%",zIndex:999}}>
                    <NavBar
                        mode="light"
                        icon={<Icon type="left" style={{color:" #f8a83f"}} />}
                        onLeftClick={()=>{window.history.back(-1)}}
                    >调整比例记录</NavBar>
                </div>
                <WhiteSpace />
                <WhiteSpace />
                <WhiteSpace />
                <WhiteSpace size="lg" />

                <div>

                    <List renderHeader={()=>this.state.comBaseName+"调仓记录"}>

                        {(()=>{return this.state.changeList.map((item,index)=>{
                            var timechange=myFunction(item.gmtCreate)
                            console.log(timechange)
                            console.log(typeof item.gmtCreate)
                            console.log(typeof item.gmtModified)
                            return(
                                <Link to={{pathname:"/changeListDetail",state:{adjustId:item.adjustId}}}>
                                    <Item
                                        multipleLine
                                        extra={
                                            <div>
                                                <p style={{marginBottom:13,fontSize:"18px",color:"red"}}>状态</p>
                                                <p style={{color:"#f8a83f",fontSize:"18px"}}>{item.adjustStatus}</p>
                                            </div>}
                                        // onClick={this.seeDetail}
                                    >
                                        {/*{item.comBaseName}*/}
                                        <Brief>
                                            {<div>
                                                <p>{"创建时间："+myFunction(item.gmtCreate)}</p>
                                                <p>{"修改时间："+myFunction(item.gmtModified)}</p>
                                                <p>{"订单号："+item.logicId}</p>
                                            </div>}
                                        </Brief>
                                    </Item>
                                </Link>
                            )
                        })
                        })()}

                    </List>

                </div>
            </div>
        );
    }
}
